using System.Collections.ObjectModel;
using HMCollada.FX;
using HMCollada.Core;
using System.Xml;

namespace HMCollada.Core {
    internal struct HMColladaSource {
        internal string id;
        internal string name;
        internal HMColladaAsset asset;
        internal HMColladaValueArray array;
        internal HMColladaTechniqueCommon technique_common;
        internal Collection<HMColladaTechnique> technique;
    }
}

namespace HMCollada {
    internal partial class HMColladaLoader {
        private static HMColladaSource LoadSource() {
            HMColladaSource newSource = new HMColladaSource();
            newSource.id = colladaReader.GetAttribute("id");
            newSource.name = colladaReader.GetAttribute("name");

            newSource.technique = new Collection<HMColladaTechnique>();

            if (!colladaReader.IsEmptyElement) colladaReader.Read();
            do {
                if (colladaReader.NodeType != XmlNodeType.EndElement) {
                    switch (colladaReader.Name) {
                        case "asset": newSource.asset = LoadAsset(); break;
                        case "IDREF_array": newSource.array = LoadValueArray(typeof(string)); break;
                        case "Name_array": newSource.array = LoadValueArray(typeof(string)); break;
                        case "bool_array": newSource.array = LoadValueArray(typeof(bool)); break;
                        case "float_array": newSource.array = LoadValueArray(typeof(float)); break;
                        case "int_array": newSource.array = LoadValueArray(typeof(int)); break;
                        case "technique_common": newSource.technique_common = LoadTechniqueCommon(); break;
                        case "technique": newSource.technique.Add(LoadTechnique()); break;
                    }
                }

                if (!colladaReader.IsEmptyElement) colladaReader.Read();
            } while (colladaReader.Name != "source");

            if (colladaReader.IsEmptyElement) colladaReader.Read();
            return newSource;
        }
    }
}